<template>
    <el-container class="layout-container">
      <el-aside :width="isCollapse?'64px':'200px'" class="aside">
        <div class="logo" :class="{minLogo:isCollapse}">
        </div>
        <el-menu
        default-active="/"
        class="nav-menu"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        :collapse="isCollapse"
        :collapse-transition="false"
        router
        >
        <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/articles">
          <i class="el-icon-document"></i>
          <span slot="title">内容管理</span>
        </el-menu-item>
        <el-menu-item index="/image">
          <i class="el-icon-picture"></i>
          <span slot="title">素材管理</span>
        </el-menu-item>
        <el-menu-item index="/addArticle">
          <i class="el-icon-s-promotion"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
        <el-menu-item index="/comment">
          <i class="el-icon-chat-dot-round"></i>
          <span slot="title">评论管理</span>
        </el-menu-item>
        <el-menu-item index="/fans">
          <i class="el-icon-setting"></i>
          <span slot="title">粉丝管理</span>
        </el-menu-item>
        <el-menu-item index="3">
            <i class="el-icon-setting"></i>
            <span slot="title">个人设置</span>
        </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
            <div>
              <i :class="isCollapse?'el-icon-s-unfold':'el-icon-s-fold'" style="cursor:pointer" @click="isCollapse=!isCollapse"></i>
              <span>江苏传智播客科技教育有限公司</span>
            </div>
            <el-dropdown>
          <!-- 默认插槽：用来显示触发开关 -->
          <div class="avatar-wrap">
            <img class="avatar" :src="user.photo" alt="">
            <span>{{user.name}}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
          <!--具名插槽：用来显示下拉内容 -->
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>设置</el-dropdown-item>
            <el-dropdown-item @click.native="hQuit">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        </el-header>
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
</template>
<script>
export default {
  data () {
    return {
      isCollapse: false,
      user: {
        name: '',
        photo: ''
      }
    }
  },
  created () {
    this.$axios({
      method: 'GET',
      url: '/mp/v1_0/user/profile'
    }).then(res => {
      console.log(res)
      this.user.name = res.data.data.name
      this.user.photo = res.data.data.photo
    }).catch(err => {
      console.log(err)
      this.$message.error('获取个人信息失败')
      localStorage.removeItem('token')
      this.$router.push('/login')
    })
  },
  methods: {
    hQuit () {
      this.$confirm('确定要退出吗?').then(() => {
        localStorage.removeItem('token')
        this.$router.push('/login')
      }).catch(() => {
        this.$message('阁下，请继续留赏')
      })
    }
  }
}
</script>

<style lang="less">
.layout-container {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

.aside {
  background-color: #002033;
  .el-menu {
    border-right: none;
  }
  .logo{
      width: 100%;
      height: 60px;
      background: #002244 url(../assets/logo_admin.png) no-repeat center / 140px auto;
    }
    // 覆盖background 的图片和大小，类写在logo的下方。
    .minLogo{
      background-image: url(../assets/logo_admin_01.png);
      background-size: 36px auto;
    }
}
.nav-menu {
  .iconfont {
    margin-right: 10px;
    padding-left: 5px;
  }
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ccc;
  .avatar-wrap {
    display: flex;
    align-items: center;
    .avatar {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      margin-right: 10px;
    }
  }
}

.main {
  background-color: #e9eef3;
}
</style>
